import json
import requests


# 读取JSON文件
def read_json_file(file_path):
    with open(file_path, 'r') as file:
        data = json.load(file)
    return data


# 调用GET接口
def call_get_api(url):
    response = requests.get(url)
    return response.text


# 调用POST接口
def call_post_api(url, data):
    headers = {
        'Content-Type': 'application/json'  # 假设接口需要JSON格式的数据
    }
    response = requests.post(url, json=data, headers=headers)
    return response


def main():
    # JSON文件路径
    file_path = 'data.json'

    # API URL
    get_api_url = 'http://localhost:8080/health-check'
    api_url = 'http://localhost:8080/parse'

    # 读取JSON数据
    data_list = read_json_file(file_path)

    # 循环调用API
    response = call_get_api(get_api_url)
    print(response)

    for data in data_list:
        response = call_post_api(api_url, data)
        print(f"Response Code: {response.status_code}, Response Text: {response.text}")
        # for i in range(10) :
        #     data['name'] = 'BOPBIZ1116CNY'+str(i)
        #     print(data['name'])


if __name__ == "__main__":
    main()
